package com.xposed.aliproxy.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xposed.aliproxy.R;

public class AlertDialog {
    private Context context;
    private Dialog dialog;
    private LinearLayout linearLayout;
    private TextView tvTitle;
    private TextView tvMsg;
    private Button btnNeg;
    private Button btnPos;
    private ImageView imageView;
    private Display display;
    private boolean f1891j = false;
    private boolean f1892k = false;
    private boolean f1893l = false;
    private boolean f1894m = false;

    /* compiled from: AlertDialog */
    /* renamed from: view.a$3 */
    class C06573 implements OnClickListener {
        C06573() {
        }

        public void onClick(View view) {
            AlertDialog.this.dialog.dismiss();
        }
    }

    public AlertDialog(Context context) {
        this.context = context;
        this.display = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    }

    /* renamed from: a */
    public AlertDialog initDialog() {
        View inflate = LayoutInflater.from(this.context).inflate(R.layout.view_alertdialog, null);
        this.linearLayout = (LinearLayout) inflate.findViewById(R.id.lLayout_bg);
        this.tvTitle = (TextView) inflate.findViewById(R.id.txt_title);
        this.tvTitle.setVisibility(View.GONE);
        this.tvMsg = (TextView) inflate.findViewById(R.id.txt_msg);
        this.tvMsg.setVisibility(View.GONE);
        this.btnNeg = (Button) inflate.findViewById(R.id.btn_neg);
        this.btnNeg.setVisibility(View.GONE);
        this.btnPos = (Button) inflate.findViewById(R.id.btn_pos);
        this.btnPos.setVisibility(View.GONE);
        this.imageView = (ImageView) inflate.findViewById(R.id.img_line);
        this.imageView.setVisibility(View.GONE);
        this.dialog = new Dialog(this.context, R.style.AlertDialogStyle);
        this.dialog.setContentView(inflate);
        this.linearLayout.setLayoutParams(new LayoutParams((int) (((double) this.display.getWidth()) * 0.85d), -2));
        return this;
    }

    public AlertDialog setTitle(String str) {
        this.f1891j = true;
        if ("".equals(str)) {
            this.tvTitle.setText("标题");
        } else {
            this.tvTitle.setText(str);
        }
        return this;
    }

    public AlertDialog setContent(String str) {
        this.f1892k = true;
        if ("".equals(str)) {
            this.tvMsg.setText("内容");
        } else {
            this.tvMsg.setText(str);
        }
        return this;
    }

    public AlertDialog setCancleable(boolean z) {
        this.dialog.setCancelable(z);
        return this;
    }

    public AlertDialog setBtnPostive(String str, final OnClickListener onClickListener) {
        this.f1893l = true;
        if ("".equals(str)) {
            this.btnPos.setText("确定");
        } else {
            this.btnPos.setText(str);
        }
        this.btnPos.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                onClickListener.onClick(view);
                AlertDialog.this.dialog.dismiss();
            }
        });
        return this;
    }

    public AlertDialog setBtnNagtivie(String str, final OnClickListener onClickListener) {
        this.f1894m = true;
        if ("".equals(str)) {
            this.btnNeg.setText("取消");
        } else {
            this.btnNeg.setText(str);
        }
        this.btnNeg.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                onClickListener.onClick(view);
                AlertDialog.this.dialog.dismiss();
            }
        });
        return this;
    }

    private void setDefault() {
        if (!(this.f1891j || this.f1892k)) {
            this.tvTitle.setText("提示");
            this.tvTitle.setVisibility(View.VISIBLE);
        }
        if (this.f1891j) {
            this.tvTitle.setVisibility(View.VISIBLE);
        }
        if (this.f1892k) {
            this.tvMsg.setVisibility(View.VISIBLE);
        }
        if (!(this.f1893l || this.f1894m)) {
            this.btnPos.setText("确定");
            this.btnPos.setVisibility(View.VISIBLE);
            this.btnPos.setBackgroundResource(R.drawable.alertdialog_single_selector);
            this.btnPos.setOnClickListener(new C06573());
        }
        if (this.f1893l && this.f1894m) {
            this.btnPos.setVisibility(View.VISIBLE);
            this.btnPos.setBackgroundResource(R.drawable.alertdialog_right_selector);
            this.btnNeg.setVisibility(View.VISIBLE);
            this.btnNeg.setBackgroundResource(R.drawable.alertdialog_left_selector);
            this.imageView.setVisibility(View.VISIBLE);
        }
        if (this.f1893l && !this.f1894m) {
            this.btnPos.setVisibility(View.VISIBLE);
            this.btnPos.setBackgroundResource(R.drawable.alertdialog_single_selector);
        }
        if (!this.f1893l && this.f1894m) {
            this.btnNeg.setVisibility(View.VISIBLE);
            this.btnNeg.setBackgroundResource(R.drawable.alertdialog_single_selector);
        }
    }

    public void showDialog() {
        setDefault();
        this.dialog.show();
    }
}
